// pages/admin-login/admin-login.js
const db = wx.cloud.database()
Page({
  adminLogin: function (e) {
    let admin = e.detail.value
    console.log(e)
    if (admin.name && admin.password) {
      db.collection('admin').where({
        name: admin.name,
        password: admin.password
      }).get({
        success: function (res) {
          console.log(res)
          if (res.data.length> 0) {
            wx.showToast({
              title: '账户或密码错误',
              icon: 'none'
            })
          } else {
            wx.navigateTo({
              url: '/pages/admin-index/admin-index',
            })
          }
        },
        fail: function (res) {
          console.log(res)
        }
      })
    } else {
      wx.showToast({
        title: '信息未填写完整',
        icon: 'none'
      })
    }
  }
})